/**
 * 
 */
package net.goodapp;


import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import net.goodapp.util.JavaGenerator;
import net.goodapp.util.PdmReader;
import net.goodapp.util.XMLGenerator;

/**
 * @author zhou.jin-qiao
 * 程序启动类
 */
public class MainClass {
	private static final Log logger = LogFactory.getLog(MainClass.class);
	/**
	 * UTF-8编码
	 */
	public static final String UTF8ENCODING="UTF-8";
	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		logger.info("start application.");
		//XMLGenerator.generateConfigurationXML();
		
		//List<TableInfo> tableInfos=XMLGenerator.readConfigurationXML("javaDatabaseconfig.xml");
		//JavaGenerator generator=new JavaGenerator(tableInfos);
		//generator.initVelocity();
		//generator.generateModel();
		//generator.generateDAO();
		//generator.generateMyBatisXMLMapper();
		//generator.generateService();
		//generator.generateServiceImpl();
		
		
		//PdmReader pdmReader=new PdmReader("RDPManagement.pdm");
		//pdmReader.geTableInfos();
		//regTest();
		//pathAndFileTest();
		logger.info("end application.");
	}
	
	private static void queryDemo(){
		String url="mysql://inre.tpddns.cn:3306/OperationTicket?useUnicode=true";
		String sql="select * from tblUser where Id=? and name=?";
		Connection connection=null;
		PreparedStatement pstmt=null;
		ResultSet resultSet=null;
		try {
			connection=DriverManager.getConnection(url);
			//connection.prepareStatement(sql)
			pstmt=connection.prepareStatement(sql);
			pstmt.setInt(0, 20);
			pstmt.setString(1,"zhangsan");
			resultSet=pstmt.executeQuery();
			while(resultSet.next()){
				
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private static void regTest(){
		String IntAddressRegex="(\\w{4})/(\\w{4})(\\w{4})(\\d+)\\.(\\w+)(\\.(\\w+))?";
		String input="TRIP/GOINGGIO1.DPCSO8.stVal,TRIP/GOINGGIO1.DPCSO7.stVal,TRIP/GOINGGIO1.DPCSO12.stVal,PISV/SVINTCTR3.Amp2";
		Pattern p = Pattern.compile(IntAddressRegex);
		Matcher matcher=p.matcher(input);
		while (matcher.find()) {
			System.out.println("LdInst:"+matcher.group(1));
			System.out.println("Prefix:"+matcher.group(2));
			System.out.println("LnClass:"+matcher.group(3));
			System.out.println("LnInst:"+matcher.group(4));
			System.out.println("DoName:"+matcher.group(5));
			System.out.println("DaName:"+matcher.group(7));
			System.out.println("--------------------------");
		}
	}
	
	private static void pathAndFileTest() throws Exception{
		String pathRoot="C:\\Users\\zhou.jin-qiao\\Desktop\\";
		File file=new File(pathRoot);
		String line=null;
		for (File childFile : file.listFiles()) {
			line=String.format("Name:%s,IsHidden:%s,isDirectory:%s,absolutePath:%s,canonicalPath:%s,isAbsolute:%s", 
					childFile.getName(),childFile.isHidden(),
					childFile.isDirectory(),childFile.getAbsolutePath(),
					childFile.getCanonicalPath(),childFile.isAbsolute());
			System.out.println(line);
		}
	}

}
